home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / AmigaOS3.5 / IPop / cx.c < prev    next >
C/C++ Source or Header  |  2000-05-16  |  3KB  |  134 lines

  1. #ifndef __COMMON_H__
  2. #include "common.h"
  3. #endif /* __COMMON_H__ */
  4.  
  5. extern struct PopData *pd;
  6.  
  7. struct Library *CxBase;
  8.  
  9. /*
  10.  * ho hum..the lowly life of a commodity
  11.  * maybe we should commit Cxcide
  12.  */
  13. VOID disposeCx(VOID)
  14. {
  15.    if(pd->pd_cxBroker)
  16.    {
  17.       DeleteCxObjAll(pd->pd_cxBroker);
  18.       pd->pd_cxBroker = NULL;
  19.    }
  20.    if(CxBase)
  21.    {
  22.       CloseLibrary((struct Library*)CxBase);
  23.    }
  24. }
  25.  
  26. /*
  27.  * Molson Ice...but uhm..beware the penguin
  28.  */
  29. BOOL createCx(struct MsgPort *port)
  30. {
  31.    struct NewBroker nb;
  32.    CxObj *filter;
  33.  
  34.    disposeCx();
  35.  
  36.    if(!(CxBase = (struct Library*)OpenLibrary("commodities.library", 40)))
  37.    {
  38.       return(FALSE);
  39.    }
  40.  
  41.    nb.nb_Version         = NB_VERSION;
  42.    nb.nb_Name            = "IPop";
  43.    nb.nb_Title           = VERS;
  44.    nb.nb_Descr           = "AppIcon POP Checker";
  45.    nb.nb_Unique          = NBU_NOTIFY | NBU_UNIQUE;
  46.    nb.nb_Pri             = pd->pd_cxPriority;
  47.    nb.nb_Port            = port;
  48.    nb.nb_ReservedChannel = NULL;
  49.    nb.nb_Flags           = COF_SHOW_HIDE;
  50.  
  51.    if(pd->pd_cxBroker = CxBroker(&nb, NULL))
  52.    {
  53.       /* install a hotkey for popping up window   */
  54.       filter = CxFilter(pd->pd_cxPopKey);
  55.       AttachCxObj(filter, CxSender(port, 86));
  56.       AttachCxObj(filter, CxTranslate(NULL));
  57.       AttachCxObj(pd->pd_cxBroker, filter);
  58.  
  59.       if(CxObjError(pd->pd_cxBroker) == 0)
  60.       {
  61.          ActivateCxObj(pd->pd_cxBroker, 1);
  62.          return(TRUE);
  63.       }
  64.       DeleteCxObjAll(pd->pd_cxBroker);
  65.    }
  66.    return(FALSE);
  67. }
  68.  
  69. /*
  70.  * handle the commodity
  71.  */
  72. BOOL processCxMsg(CxMsg *msg)
  73. {
  74.    ULONG msgID;
  75.    ULONG msgType;
  76.  
  77.    msgID   = CxMsgID(msg);
  78.    msgType = CxMsgType(msg);
  79.    ReplyMsg((struct Message *)msg);
  80.  
  81.    switch(msgType)
  82.    {
  83.       case CXM_IEVENT:
  84.       {
  85.          switch(msgID)
  86.          {
  87.             case 86:
  88.             {
  89.                openHWindow(pd);
  90.                break;
  91.             }
  92.          }
  93.          break;
  94.       }
  95.  
  96.       case CXM_COMMAND:
  97.       {
  98.          switch(msgID)
  99.          {
  100.             case CXCMD_DISABLE:  /* disable ourselves */
  101.             {
  102.                ActivateCxObj(pd->pd_cxBroker, 0);
  103.                break;
  104.             }
  105.  
  106.             case CXCMD_ENABLE:   /* enable ourselves */
  107.             {
  108.                ActivateCxObj(pd->pd_cxBroker, 1);
  109.                break;
  110.             }
  111.  
  112.             case CXCMD_APPEAR:
  113.             case CXCMD_UNIQUE:
  114.             {
  115.                openHWindow(pd);
  116.                break;
  117.             }
  118.  
  119.             case CXCMD_DISAPPEAR:
  120.             {
  121.                closeHWindow(pd);
  122.                break;
  123.             }
  124.  
  125.             case CXCMD_KILL:     /* mama tryme */
  126.             {
  127.                return(FALSE);
  128.             }
  129.          }
  130.       }
  131.    }
  132.    return(TRUE);
  133. }
  134.